Home:ALL Converter>How prevent errors on windows when i use Qt Android Extras C++ Classes

How prevent errors on windows when i use Qt Android Extras C++ Classes

Ask Time:2018-07-18T12:42:13         Author:mohsen

Json Formatter

I used the solution of below question for open file on Android.

Qt/Necessitas - reasonable QFileDialog replacement/skin?

But it works just on android,this codes (Qt Android Extras C++ Classes) don't run on windows?

for example i got the below errors?

#include<QAndroidJniObject>
#include<QtAndroid>
#include<QAndroidActivityResultReceiver>

Cannot open include file: 'QAndroidJniObject': No such file or directory

I used this for solving

#if defined(Q_OS_ANDROID)
#include<QAndroidJniObject>
#include<QtAndroid>
#include<QAndroidActivityResultReceiver>
#endif

but when i used this I have got another errors?

 class ResultReceiver:public QAndroidActivityResultReceiver//error :'QAndroidActivityResultReceiver': base class undefined
{
    AndroidFileDialog *_dialog;

public:
    ResultReceiver(AndroidFileDialog *dialog);

    virtual ~ResultReceiver();
    void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data);
    QString uriToPath(QAndroidJniObject uri);
};

'QAndroidActivityResultReceiver': base class undefined

Author:mohsen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51393711/how-prevent-errors-on-windows-when-i-use-qt-android-extras-c-classes
Mohammad Kanan :

The class ResultReceiver inherits QAndroidActivityResultReceiver (from Android Extras) which you correctly stopped including for windows OS, thus the error. \nYou must have 2 variants of ResultReceiver class, one for Windows, another for Android. When you design it for Windows you should not inherit QAndroidActivityResultReceiver and use QFileDialog. \nIn the same way you solved the import issues with Qt pre-processor, you could define ResultReceiver class , for example:\n\n#if defined(Q_OS_ANDROID)\n\nclass AndroidFileDialog : public QObject\n{\n Q_OBJECT\n ...\nprivate:\n class ResultReceiver : public QAndroidActivityResultReceiver {\n AndroidFileDialog *_dialog;\n ...\n };\n ...\n ...\n};\n#else\nclass ResultReceiver // Here do not inherit classes from Android Extras\n{\n QFileDialog *_dialog; // use standard Qt C++ classes \n ...\n ...\n};\n#endif //Q_OS_ANDROID\n",
2018-07-18T15:20:07
yy